#ifndef SONGTREE_H_
#define SONGTREE_H_

#include <qtimer.h>
/* #include <mythtv/uitypes.h> */
/* #include <mythtv/uilistbtntype.h> */
/* #include <mythtv/xmlparse.h> */
#include <mythtv/mythdialogs.h>
#include <mythtv/mythdbcon.h>

#include "songinfo.h" 
#include "CDGWidgetBase.h"

/**************************************************************************
    KaraokeTreeRoot - helper class holding tree root details
 **************************************************************************/
class KaraokeTreeRoot
{
  public:
    KaraokeTreeRoot(const QString& levels, const QString& filter)
      : m_levels(QStringList::split(" ", levels))
      , m_filter(filter)
    {
    }

    ~KaraokeTreeRoot()
    {
    }

    unsigned getDepth() const                   { return m_levels.size(); }
    const QString& getLevel(unsigned i) const   { return m_levels[i]; }
    const QString& getFilter() const            { return m_filter; }

  private:
    QStringList m_levels;
    QString m_filter;
};

/**************************************************************************
    KaraokeTreeItem - helper class supplying data and methods to each node
 **************************************************************************/
class KaraokeTreeItem : public QObject
{
  public:
    KaraokeTreeItem(KaraokeTreeRoot* root)
      : m_root(root)
      , m_songInfo(0)
      , m_depth(0)
      , m_isFilled(false)
    {
    }

    ~KaraokeTreeItem()
    {
        if (m_songInfo)
            delete m_songInfo;
    }

    bool isFilled() const             { return m_isFilled; }
    bool isLeaf() const               { return m_depth == m_root->getDepth(); }

    const QString& getLevel() const   { return m_root->getLevel(m_depth - 1); }
    SongInfo* getSongInfo() const     { return m_songInfo; }
    QString getFillSql(QString layer) const;

    void setFilled(bool isFilled)     { m_isFilled = isFilled; }

    KaraokeTreeItem* createChild(QSqlQuery *query) const;

  private:
    KaraokeTreeRoot* m_root;
    SongInfo* m_songInfo;

    unsigned m_depth;
    bool m_isFilled;
};


class SongTree : public MythThemedDialog
{
    Q_OBJECT

 public:
    typedef QValueVector<int> IntVector;

    SongTree(MythMainWindow *parent, QString windowName,
           QString themeFilename, const char *name = 0);
    ~SongTree();

 public slots:
    void handleTreeListSelection(int, IntVector*);
    void handleTreeListEntry(int, IntVector*);
    void showImageTimeout(void) ;

 protected:
    void keyPressEvent(QKeyEvent *e);

 private:
    void wireUpTheme(void);
    void fillNode(GenericTree *node);
    void Playsong(SongInfo *songdata);

    QValueVector<KaraokeTreeRoot *> m_karaokeTreeRoots;
    QValueVector<KaraokeTreeItem *> m_karaokeTreeItems;

    GenericTree           *m_karaokeTree;
    UIManagedTreeListType *m_karaokeTreeUI;

    QTimer      *imagetimer;

    CDGWidgetBase *cdg;
    UITextType    *m_karaokeTitle;
    UITextType    *m_karaokePath;
    UIImageType   *m_karaokeImage;

};

#endif
